package com.aaa.controller.jl;

import com.aaa.pojo.Menu;
import com.aaa.pojo.jl.ResltBean;
import com.aaa.service.jl.LoginService;
import com.aaa.service.jl.MenuService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;



@RestController
public class loginController {
    @Autowired
    private MenuService menuService;
    @Autowired
    private LoginService loginService;
    @RequestMapping("/login")
    public ResltBean login(@RequestBody Map<String,Object> map, HttpSession session) {
        boolean check = loginService.check(map);
        if (check){
            Map<String, Object> userInfo = loginService.findUserInfoByName(map);
            userInfo.remove("password");
            userInfo.remove("salt");
            session.setAttribute("userInfo",userInfo);
        }
        Map<String, List<Menu>> menuMap = menuService.findAll(map.get("searchUserName").toString());
        ResltBean resultBean = new ResltBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        session.setAttribute("menuMap", menuMap);
        return resultBean;
    }

}